package com.hkfg.service.impl;

import com.hkfg.dao.BlogDao;
import com.hkfg.dao.UserDao;
import com.hkfg.domain.Blog;
import com.hkfg.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlogServiceImpl implements BlogService {

    @Autowired
    private BlogDao blogDao;
    @Autowired
    private UserDao userDao;

    @Override
    public List<Blog> selectUserBlog(int id) {

        return blogDao.selectBlogById(id);

    }

    @Override
    public int buildBlog(Blog blog) {
        System.out.println("新建了blog");
        if(blogDao.buildBlog(blog) > 0){
            return 1; // 成功
        }else {
            return 0;   // defeat
        }
    }

    @Override
    public Blog getBlogById(int id) {
        return blogDao.getBLogById(id);
    }

    @Override
    public int deleteBlogById(int id) {
        if( blogDao.deleteBlogById(id) > 0){
            return 1;   // 成功删除
        }else {
            return 0;   // 删除失败
        }
    }

    @Override
    public int modifyBlog(int id, String title, String content) {   // id是blog的
       return blogDao.modifyBlog(id, title, content);
    }
}
